import { defineStore } from "pinia";

interface IState {
    navOpen: boolean;
    isDark: boolean;
    newsOpen: boolean;
    isToTop: boolean;
    maxChart: boolean;
    chartsHeight: number,
    heightData: number,
    popPosition: boolean
    isMobile: boolean,
    snackbar: boolean,
    timerStr: String,
    contentText: any,
    barType: string,
    whaleList: any[],
    mediumChart: boolean,
    chartsLoading: boolean,
    isOnEnd:boolean
}

export const useLayout = defineStore("layout", {
    state: (): IState => ({
        navOpen: true,
        isDark: true,
        newsOpen: true,
        isToTop: false,
        maxChart: true,
        chartsHeight: 0,
        heightData: 132,
        popPosition: false,
        isMobile: false && checkMobile(),
        snackbar: false,
        timerStr: "",
        whaleList: [],
        contentText: {},
        barType: "",
        mediumChart: false,
        chartsLoading: false,
        isOnEnd:false

    }),
    getters: {},
    actions: {
        toggleIsOnEnd(flag: boolean) {
            this.isOnEnd = flag
        },
        toggleMedium(flag: boolean) {
            console.log("000000")
            this.mediumChart = flag
        },
        toggleChartsLoading(flag: boolean) {
            console.log("000000")
            this.chartsLoading = flag
        },
        setText(time: string, text: object, type: string) {
            // this.timerStr = time
            // this.contentText = text,
            // this.barType = type
            this.whaleList.push({
                timerStr: time,
                barType: type,
                contentText: text
            })
            // console.log('查看whaleList信息 $$$$$$$$$$$$$$$$$$$$$$', this.whaleList)
        },
        changeWhaleList(list: any) {
            this.whaleList = list
            // console.log('改变', this.whaleList)
        },
        changeSnackbar(flag: boolean) {
            this.snackbar = flag;
        },
        toggleSnackbar() {
            let dom = document.querySelector(".v-overlay__content ")
            console.log(dom)
            this.snackbar = !this.snackbar;
        },
        // 图表最大化
        chartsMax(val: any) {
            this.chartsHeight = val;
        },
        changePopPosition(val: boolean) {
            console.log("changePopPosition", val)
            this.popPosition = val;
        },
        toggleNavOpen() {
            this.navOpen = !this.navOpen;
        },
        toggleNewsOpen() {
            this.newsOpen = !this.newsOpen;
        },
        closeNesOpen() {
            console.log('关闭右侧栏！！！！！！！！！！')
            this.newsOpen = false
        },
        openNesOpen() {
            console.log('打开右侧栏！！！！！！！！！！')
            this.newsOpen = true
        },
        changeNavOpen(val: boolean) {
            this.navOpen = val;
        },
        toggleIsDark() {
            this.isDark = !this.isDark;
        },
        changeIsDark(val: boolean) {
            this.isDark = val;
        },
        changeIsToTop(val: boolean) {
            this.isToTop = val;
        },
        toggleSize() {
            console.log("000000")
            this.maxChart = !this.maxChart;
        }
    }
});

function checkMobile() {
    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}